package cn.com.twoke.application.game.mario.core.ecs.component;

import lombok.extern.slf4j.Slf4j;

import java.util.HashSet;
import java.util.Set;

@Slf4j
public class InputState {
    private final Set<Integer> pressedKeys = new HashSet<>();
    private final Set<Integer> newPressedKeys = new HashSet<>();
    private int mouseX, mouseY;
    
    public void keyPressed(int keyCode) {
        pressedKeys.add(keyCode);
        newPressedKeys.add(keyCode);
        log.debug("pressed key code: {}", keyCode);
    }
    
    public void keyReleased(int keyCode) {
        pressedKeys.remove(keyCode);
    }
    
    public void mouseMoved(int x, int y) {
        mouseX = x;
        mouseY = y;
    }
    
    public boolean isKeyPressed(int keyCode) {
        return pressedKeys.contains(keyCode);
    }
    
    public boolean wasKeyPressed(int keyCode) {
        return newPressedKeys.contains(keyCode);
    }
    
    public void clearNewKeys() {
        newPressedKeys.clear();
    }
    
    public int getMouseX() { return mouseX; }
    public int getMouseY() { return mouseY; }
}